package com.gilgamesh.mall.product.sql;

import com.gilgamesh.mall.sdk.bean.product.ProductDetailEntity;
import com.gilgamesh.mall.sdk.util.BeanUtil;
import com.gilgamesh.mall.sdk.util.StringUtil;


/**
 * Created by Peiyao.Wang on 2021/1/13
 *
 * @author Peiyao.Wang
 * @date 2021/1/13
 */

public class ProductDetailSql {
    public String listProductDetails(ProductDetailEntity productDetailEntity){
        StringBuilder sb = new StringBuilder();
        sb.append("select * from t_product_detail");
        if(BeanUtil.isLogicalNull(productDetailEntity)){
            return sb.toString();
        }
        int times = 0;
        if (productDetailEntity.getId() != null){
            if(times == 0){
                sb.append(" where ");
            }else if(times > 0){
                sb.append("and");
            }
            times++;
            sb.append("id = #{id}");
        }
        if(StringUtil.isNotEmpty(productDetailEntity.getSkuCode())){
            if(times == 0){
                sb.append(" where ");
            }else if(times > 0){
                sb.append(" and ");
            }
            times++;
            sb.append("sku_code = #{skuCode}");
        }
        if(StringUtil.isNotEmpty(productDetailEntity.getProductCode())){
            if(times == 0){
                sb.append(" where ");
            }else if(times > 0){
                sb.append(" and ");
            }
            times++;
            sb.append("product_code = #{productCode}");
        }
        if(StringUtil.isNotEmpty(productDetailEntity.getShoppingCartDescription())){
            if(times == 0){
                sb.append(" where ");
            }else if(times > 0){
                sb.append(" and ");
            }
            times++;
            sb.append("shopping_cart_description = #{shoppingCartDescription}");
        }
        if(productDetailEntity.getCreateTime() != null){
            if(times == 0){
                sb.append(" where ");
            }else if(times > 0){
                sb.append(" and ");
            }
            times++;
            sb.append("create_time =#{createTime}");
        }
        if(productDetailEntity.getOriginalPrice() != null){
            if(times == 0){
                sb.append(" where ");
            }else if(times > 0){
                sb.append(" and ");
            }
            times++;
            sb.append("original_price = #{originalPrice}");
        }
        if(productDetailEntity.getCurrentPrice() != null){
            if(times == 0){
                sb.append(" where ");
            }else if(times > 0){
                sb.append(" and ");
            }
            times++;
            sb.append("current_price = #{currentPrice}");
        }
        return sb.toString();
    }

}
